export const reconstructionStuData = (data) => {
  if (!Array.isArray(data)) return [];
  let tmpData = [];
  data.forEach((item, i) => {
    //有二级数据的进行处理
    if (Array.isArray(item.sku_item) && item.sku_item.length > 0) {
      //循环成绩
      item.sku_item.forEach((sub, j) => {
        let subData = {};
        if (j == 0) {
          //子项第1行数据，和姓名信息同行
          subData = Object.assign(
            {
              columnIndex1: {
                columnIndex: 1,
                rowspan: item.sku_item.length,
                colspan: 1,
              },
            },
            item,
            sub
          );
          subData["allAmount"] = item.sku_item.reduce((amount, value) => {
            return amount + value.amount;
          }, 0);

          subData["columnIndex0"] = {
            columnIndex: 0,
            rowspan: item.sku_item.length,
            colspan: 1,
          };

          subData["columnIndex10"] = {
            columnIndex: 10,
            rowspan: item.sku_item.length,
            colspan: 1,
          };
          subData["columnIndex8"] = {
            columnIndex: 8,
            rowspan: item.sku_item.length,
            colspan: 1,
          };
          subData["columnIndex9"] = {
            columnIndex: 9,
            rowspan: item.sku_item.length,
            colspan: 1,
          };
        }
        //其他行数据无须添加 姓名字段信息（第一行数据会合并到结束位置，填充后也会被覆盖）
        else {
          subData = Object.assign(
            { columnIndex1: { columnIndex: 1, rowspan: 0, colspan: 0 } },
            sub
          );

          //总分和满分总分 被合并部分单元格填写为0
          subData["columnIndex0"] = { columnIndex: 0, rowspan: 0, colspan: 0 };
          subData["columnIndex7"] = { columnIndex: 10, rowspan: 0, colspan: 0 };
          subData["columnIndex8"] = { columnIndex: 8, rowspan: 0, colspan: 0 };
          subData["columnIndex9"] = { columnIndex: 9, rowspan: 0, colspan: 0 };
        }
        //if end
        tmpData.push(subData);
      });
    }
    //无子项数据，保留当前位置输出
    else {
      tmpData.push(
        Object.assign(
          { columnIndex1: { columnIndex: 1, rowspan: 1, colspan: 1 } },
          item
        )
      );
    }
  });
  return tmpData;
};
